﻿using System;
using System.Reflection;

namespace UnitTesting.Fixturing
{
	class ReflectionValueProvider : ReflectionValueProviderBase
	{
		readonly IConstructorProvider _constructorProvider;

		internal ReflectionValueProvider(IValueProvider valueProvider, IFreezable freezable, object fixtureOptoins)
			: this(valueProvider, new ConstructorsForDynamicProxy(), new CurrentActivator(), freezable, fixtureOptoins)
		{
		}

		internal ReflectionValueProvider(IValueProvider valueProvider, IActivator activator, IFreezable freezable, object fixtureOptoins)
			: this(valueProvider, new Constructors(Visibilities.All), activator, freezable, fixtureOptoins)
		{
		}

		internal ReflectionValueProvider(IValueProvider valueProvider, IConstructors constructors, IActivator activator, IFreezable freezable, object fixtureOptoins)
			: this(new LooseVerboseConstructorProvider(constructors), new ArgumentService(valueProvider), activator, valueProvider, freezable, fixtureOptoins)
		{
		}

		internal ReflectionValueProvider(IConstructorProvider constructorProvider,
		                                 IArgumentProvider argumentProvider,
		                                 IActivator activator,
		                                 IValueProvider valueProvider,
		                                 IFreezable freezable,
		                                 object fixtureOptoins)
			: base(argumentProvider, activator, valueProvider, freezable, fixtureOptoins)
		{
			_constructorProvider = Ensure.IsNotNull(() => constructorProvider);
		}

		protected internal override ConstructorInfo GetConstructor(Type fromType)
		{
			Ensure.IsNotNull(() => fromType);
			return _constructorProvider.GetConstructorFor(fromType);
		}

		protected ReflectionValueProvider()
		{
		}
	}
}